import Services from './services'
import _ from 'lodash'
export default {
  async getAllProducts ({state}) {
    const res = await Services.getTypeProduct()
    state.allProducts = _.values(res.data)
    console.log(state.allProducts)
    return res
  },
  async getProductInfo({state}, id) {
    if (state.productInfo._id === id) return
    const res = require('~/static/api/productInfo.json')
    console.log(res.data[id])
    state.productInfo = res.data[id]
    return res
  },
  async getTypeProduct({state}, path) {
    const res = await Services.getTypeProduct()
    state.typeProduct = res.data[path]

    return res
  },

  async getnewProduct({state}) {
    const res = await Services.getnewProduct() 
    state.typeProduct = res.data

    return res
  },

  getWechatSignature({ commit }, url) {
    return Services.getWechatSignature(url)
  },
  getUserByOAuth({ commit }, url) {
    return Services.getUserByOAuth(url)
  },
  async fetchHouses({ state }) {
    const res = await Services.fetchHouses()
    state.houses = res.data.data
    return res
  },
  async fetchCharacters({ state }) {
    const res = await Services.fetchCharacters()
    state.characters = res.data.data

    return res
  },
  async fetchCities({ state }) {
    const res = await Services.fetchCities()
    state.cities = res.data.data

    return res

  },
  async currentHouse({ state }, _id) {
    if (_id === state.currentHouse._id) return

    const res = await Services.fetchHouse(_id)
    state.currentHouse = res.data.data
    return res
  },
  async fouseProduct({ state }, _id) {
    if (_id === state.fouseProduct._id) return
    const res = await Services.fetchProduct(_id)
    state.fouseProduct = res.data.data
    return res
  },
  async fetchProducts({ state }) {
    const res = await Services.fetchProducts()
    state.products = res.data.data
    return res
  },
  async fetchPayments({ state }) {
    const res = await Services.fetchPayments()
    state.authUser = res.data.data
    return res
  },


















  async fetchPanHome({ state }) {
    const res = await Services.fetchPanHome()
    state.panHome = res.data.data[0]
    return res
  }
}